package com.bms.hystrix.service.jxgl;

import com.bms.hystrix.interfaces.jxgl.ServiceFeignByCheck;
import com.bms.hystrix.pojo.YiWuRenYuanVo;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangyujin
 * @version 1.0
 * @description CheckService.java
 * @date 2021/3/22 10:05
 */
@Service
public class CheckService {
    @Resource
    private ServiceFeignByCheck serviceFeignByCheck;

    // 通过feign调用服务模块，如果触发熔断机制，则会调用此注解fallbackMethod定义的方法
    @HystrixCommand(fallbackMethod = "checkError")
    public Map check(String name) {
        return serviceFeignByCheck.selectClient(name);
    }

    @HystrixCommand(fallbackMethod = "chaXunFenYecheckError")
    public Map chaXunFenYe(Integer page, String mingCheng) {
        System.out.println("ww:"+page+mingCheng);
        return serviceFeignByCheck.chaXunFenYe(page,mingCheng);
    }

    public Map xinZeng(@RequestBody YiWuRenYuanVo yiWuRenYuan) {
        System.out.println(yiWuRenYuan.toString()+"22222");
        return serviceFeignByCheck.xinZeng(yiWuRenYuan);
    }

    public Map<String, Object> chaxXunByTiaoJian(String name, Integer page, Integer limit) {
        return serviceFeignByCheck.chaxXunByTiaoJian(name,page,limit);
    }

    public Map chaXunFenYecheckError(Integer page,String name) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        map.put("name", name);
        map.put("page", page);
        return map;
    }

    public Map checkError(String name) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        map.put("name", name);
        return map;
    }



}

